using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace StupidSpaceThing
{
	internal class Level3_PuzzleGuide : Guide
	{
		private float scale;
		private SpriteFont font;
		private Faction faction1;
		private Faction faction2;

		public Level3_PuzzleGuide(SpriteFont font, float scale, Faction faction1, Faction faction2)
			: base(0, null) {
			this.scale = scale;
			this.font = font;
			this.faction1 = faction1;
			this.faction2 = faction2;
			this.Callback = new GuideCallback(callback);
		}

		private void callback(){
			state = GuideState.FadeIn;
		}

		private class TextBite
		{
			public readonly string Text;
			public readonly Color Color;

			public TextBite(string text, Color color) {
				this.Text = text;
				this.Color = color;
			}
		}

		public override void Draw(SpriteBatch spriteBatch) {					
			List<TextBite> bites = new List<TextBite>();
			bites.Add(new TextBite("Alpha-link to ", Color.White));
			bites.Add(new TextBite(faction1.FactionColor+"", faction1.Color));			
			bites.Add(new TextBite("'s Beta-link target and Beta-link to ", Color.White));
			bites.Add(new TextBite(faction2.FactionColor + "", faction2.Color));
						
			float totalWidth = 0;
			foreach( TextBite bite in bites ) {
				totalWidth += font.MeasureString(bite.Text).X * scale;
			}
			int leftOffset = (int)(spriteBatch.GraphicsDevice.Viewport.Width / 2 - (totalWidth) / 2);
			int topOffset = (int)(spriteBatch.GraphicsDevice.Viewport.Height / 2 - (font.MeasureString(bites[0].Text).Y * scale) / 2);

			float curOffset = 0;
			foreach( TextBite bite in bites ) {
				spriteBatch.DrawString(font, bite.Text, new Vector2(leftOffset + curOffset - 1, topOffset - 1), GetColor(Color.Black), 0, Vector2.Zero, scale, SpriteEffects.None, 0);
				spriteBatch.DrawString(font, bite.Text, new Vector2(leftOffset + curOffset, topOffset), GetColor(bite.Color), 0, Vector2.Zero, scale, SpriteEffects.None, 0);
				curOffset += font.MeasureString(bite.Text).X * scale;
			}
			base.Draw(spriteBatch);
		}
	}
}
